import { ref, computed } from 'vue';
import { stockStore } from '@/store/stock';
const store = stockStore();
export const inputFilterHook = () => {
    const inputFilter = computed(() => store.inputFilter);
    const name = ref('');
    if (inputFilter) {
        name.value = inputFilter.value;
    }
    const handleNameSearch = () => {
        store.updateNameFilter(name.value);
    };

    return {
        name,
        handleNameSearch
    };
};

export const priceFilterHook = () => {
    const priceFilter = computed(() => store.priceFilter);
    const priceValue = ref('');
    if (priceFilter) {
        priceValue.value = priceFilter.value;
    }
    const handlePriceChange = (value) => {
        store.updatePriceFilter(value);
    };
    return {
        priceValue,
        handlePriceChange
    };
};

export const marketFilterHook = () => {
    const marketFilter = computed(() => store.marketFilter);
    const marketValue = ref('');
    if (marketFilter) {
        marketValue.value = marketFilter.value;
    }
    const handleMarketChange = (value) => {
        store.updateMarketFilter(value);
    };
    return {
        marketValue,
        handleMarketChange
    };
};

export const sectorFilterHook = () => {
    const sectorFilter = computed(() => store.sectorFilter);
    const sectorValue = ref('');
    if (sectorFilter) {
        sectorValue.value = sectorFilter.value;
    }
    const handleSectorChange = (value) => {
        store.updateSectorFilter(value);
    };

    return {
        sectorValue,
        handleSectorChange
    };
};

export const conceptFilterHook = () => {
    const conceptFilter = computed(() => store.conceptFilter);
    const conceptValue = ref('');
    if (conceptFilter) {
        conceptValue.value = conceptFilter.value;
    }
    const handleConceptChange = (value) => {
        store.updateConceptFilter(value);
    };
    return {
        conceptValue,
        handleConceptChange
    };
};

export const buySellFilterHook = () => {
    const buySellFilter = computed(() => store.buySellFilter);
    const buySell = ref('');
    if (buySellFilter) {
        buySell.value = buySellFilter.value;
    }
    const handleBuySell = (value) => {
        store.updateBuySellFilter(value);
    };
    return {
        buySell,
        handleBuySell
    };
};

export const detailStockHook = () => {
    const showDetail = ref(false);
    const stockInfo = ref(null);
    const handleOpenDetail = (info) => {
        store.updateSort(true);
        stockInfo.value = info;
        showDetail.value = true;
    };
    const handleCloseDetail = () => {
        store.updateSort(false);
        stockInfo.value = null;
        showDetail.value = false;
    };
    return {
        showDetail,
        stockInfo,
        handleOpenDetail,
        handleCloseDetail
    };
};